package com.lianwei.hospital.controller;

import com.lianwei.hospital.Service.BookingInfoService;
import com.lianwei.hospital.Service.Impl.BookingInfoImpl;
import com.lianwei.hospital.module.entity.BookingInfo;
import com.lianwei.hospital.module.vo.BookingVO;
import com.lianwei.hospital.utils.PageUtil;
import com.lianwei.hospital.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/booking")
public class BookingInfoController {
    @Autowired
    private BookingInfoService bookingInfoService;

    @GetMapping("/selectById")
    public Result<BookingInfo> Select(String i) throws Exception {
        System.out.println(i+"\n\n");
        BookingInfo bookingInfo = bookingInfoService.selectByPrimaryKey(i);
        return Result.buildResult(Result.Status.OK,bookingInfo);
    }

    @PutMapping
    public Result<List<BookingInfo>> Insert(@RequestBody BookingInfo bookingInfo) throws Exception {
        System.out.println(bookingInfo);
        if(bookingInfoService.insert(bookingInfo)){
            List<BookingInfo> bookingInfoList = bookingInfoService.selectAll();
            return Result.buildResult(Result.Status.OK,bookingInfoList);
        }
        return Result.buildResult(Result.Status.BAD_REQUEST);
    }

//    @DeleteMapping
//    public Result<List<BookingInfo>> Delete(@RequestBody BookingInfo bookingInfo){
//        System.out.println(bookingInfo);
//        if(bookingInfoImpl.deleteByPrimaryKey(bookingInfo.getAId())){
//            List<Admain> admainList = admainImpl.selectAll();
//            return Result.buildResult(Result.Status.OK,admainList);
//        }
//        return Result.buildResult(Result.Status.BAD_REQUEST);
//    }

    @PostMapping
    public Result<List<BookingInfo>> Update(@RequestBody BookingInfo bookingInfo) throws Exception {
        System.out.println(bookingInfo);
        if(bookingInfoService.updateByPrimaryKey(bookingInfo)){
            List<BookingInfo> bookingInfoList = bookingInfoService.selectAll();
            return Result.buildResult(Result.Status.OK,bookingInfoList);
        }
        return Result.buildResult(Result.Status.BAD_REQUEST);
    }

    @GetMapping("/selectAll")
    public Result<PageUtil<BookingInfo>> list(@RequestBody BookingVO query) throws Exception {
        PageUtil<BookingInfo> pageUtil= bookingInfoService.findPage(query);
        return Result.buildResult(Result.Status.OK,pageUtil);
    }
}
